package service.credit.impl;

import java.util.List;

import model.grant.Customgrant;
import model.personal.Personalbasic;

import dao.CustomgrantDao;
import dao.PersonalbasicDao;
import exception.Exceptions;

import service.credit.PersonalSearchService;

public class PersonalSearchServiceImpl implements PersonalSearchService {
	private PersonalbasicDao personalbasicDao;
	private CustomgrantDao customgrantDao;

	@Override
	public List<Personalbasic> get_personalList() {
		return this.personalbasicDao.findAll();
	}

	public PersonalbasicDao getPersonalbasicDao() {
		return personalbasicDao;
	}

	public void setPersonalbasicDao(PersonalbasicDao personalbasicDao) {
		this.personalbasicDao = personalbasicDao;
	}

	@Override
	public List<Personalbasic> searchPersonByID(Integer id) {
		return this.personalbasicDao.findList("id", id);
	}

	@Override
	public List<Personalbasic> searchPersonByName(String name) {
		return this.personalbasicDao.findList("name", name);
	}

	@Override
	public Personalbasic searchOnePerson(Integer id) {
		return this.personalbasicDao.findOne("id", id);
	}

	@Override
	public Customgrant getCustomgrantByCustomId(Integer customId)
			throws Exceptions {
		if (this.customgrantDao.findByOne("customid = " + customId
				+ " and customtype = 1") != null) {
			return this.customgrantDao.findByOne("customid = " + customId
					+ " and customtype = 1");
		} else {
			throw new Exceptions("对不起，该客户尚无授信记录。不能进行此操作！");
		}
	}

	public CustomgrantDao getCustomgrantDao() {
		return customgrantDao;
	}

	public void setCustomgrantDao(CustomgrantDao customgrantDao) {
		this.customgrantDao = customgrantDao;
	}

	@Override
	public List<Personalbasic> searchPersonalbasicByIdNumber(String number) {
		return this.personalbasicDao.findList("certificatenumber", number);
	}
}
